package com.itheima.contreller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@Controller  //将该类交给spring管理
//@ResponseBody  //返回值不在进行页面跳转; 而是传递数据
//上面2注解合并为 :
@RestController //该注解是上面2个注解的合并

@RequestMapping("/user/")  //在这个路径下去找
public class UserController {

    @RequestMapping("{id}")  //这个id表示是这个方法的唯一标识
    public String restLocation(@PathVariable Integer id){ //@PathVariable :表明用这个参数接收上面的唯一标识id
        System.out.println("restful风格编程"+id);

        //restful风格它是在当前的/user这个路径下去找这个jsp页面; 所以需要将这jsp页面放在
        return "success.jsp";
    }


    /*接下来添加访问行为 :
    - GET（查询） http://localhost/user/1 GET
    - POST（保存） http://localhost/user POST
    - PUT（更新） http://localhost/user PUT
    - DELETE（删除） http://localhost/user/1  DELETE
     */
    //通过method = RequestMethod.访问行为  :设定访问行为
    //@RequestMapping(value = "{id}",method = RequestMethod.GET)//这里设定为GET行为(默认get行为)
    @GetMapping("{id}")//上面注解的简化
    public String get(@PathVariable Integer id){
        System.out.println("restful风格编程之get"+id);

        return "success.jsp";
    }

   // @RequestMapping(value = "{id}",method = RequestMethod.POST)  //保存
    @PostMapping("{id}")
    public String post(@PathVariable Integer id){
        System.out.println("restful风格编程之POST"+id);

        return "success.jsp";
    }

    //@RequestMapping(value = "{id}",method = RequestMethod.PUT)  //添加
    @PutMapping("{id}")
    public String put(@PathVariable Integer id){
        System.out.println("restful风格编程之PUT"+id);

        return "success.jsp";
    }

    //@RequestMapping(value = "{id}",method = RequestMethod.DELETE) //删除
    @DeleteMapping("{id}")
    public String delete(@PathVariable Integer id){
        System.out.println("restful风格编程之DELETE"+id);

        return "success.jsp";
    }
}
